package cn.xyy.system.api;

import cn.xyy.system.service.AuthService;
import cn.xyy.system.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import cn.xyy.common.domain.mvc.R;

/**
 * 系统文件上传、下载接口
 *
 * @author xyy
 */
@RestController
@RequestMapping(value = "/rest/sysfile")
public class SysFileRest {

	@Autowired
	private AuthService authService;
	@Autowired
	private FileService fileService;

	/**
	 * 用户头像上传
	 *
	 * @param file
	 * @return
	 */
	@RequestMapping(value = "uploadUserAvatar", method = RequestMethod.POST)
	public R uploadUserAvatar(@RequestParam MultipartFile file) {
		return R.ok(authService.updateAvatar(file));
	}

	@RequestMapping(value = "getUserAvatar/{fileName}")
	public void getUserAvatar(@PathVariable("fileName") String fileName) {
		authService.getAvatar(fileName);
	}

	/**
	 * Tinymce图片上传
	 *
	 * @param file
	 * @return
	 */
	@RequestMapping(value = "uploadTinymce", method = RequestMethod.POST)
	public R uploadTinymce(@RequestParam MultipartFile file) {
		return R.ok(fileService.uploadTinymce(file));
	}

	@RequestMapping(value = "downLoadTinymce/{fileName}")
	public void downLoadTinymce(@PathVariable("fileName") String fileName) {
		fileService.downLoadTinymce(fileName);
	}

}
